<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>客户信息列表</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/main.css">
    <script type="text/javascript">
    	function deleteOneCustomer(customerId) {
    		var sure = window.confirm("您确认删除吗？") ;
    		if(sure) {
    			window.location.href = "${pageContext.request.contextPath }/servlet/CustomerController?operate=deleteOneCustomer&customerId=" + customerId ;
    		}
    	}
    	function deleteMultiCustomers() {
    		var selected = false ;
    		//检查用户是否选择记录
    		var idsObjs = document.getElementsByName("ids") ;
    		var ids = "" ;
    		for(var i=0; i<idsObjs.length; i++) {
    			if(idsObjs[i].checked) {
    				selected = true ;
    				ids += idsObjs[i].value ;
    				if(i < idsObjs.length-1) {
    					ids += "," ;
    				}
    			}
    		}
    		if(!selected) {
    			alert("请选择要删除的记录！") ;
    			return ;
    		}
    		var sure = window.confirm("确认删除所选记录吗？") ;
    		if(sure) {
    			window.location.href="${pageContext.request.contextPath }/servlet/CustomerController?operate=deleteMultiCustomers&ids=" + ids ;
    		}
    	}
    </script>
  </head>
  
  <body>
  		<table width="88%">
  			<%@ include file="/commons/page.jsp" %>
  			<tr>
  				<td>
  					<a href="${pageContext.request.contextPath }/addCustomer.jsp ">添加</a>
  					<a href="javascript:deleteMultiCustomers()">删除</a>
  				</td>
  			</tr>
  			<tr>
  				<td>
  					<table border="1" width="100%">
  						<tr>
  							<th>选择</th>
  							<th>姓名</th>
  							<th>性别</th>
  							<th>生日</th>
  							<th>电话</th>
  							<th>邮箱</th>
  							<th>爱好</th>
  							<th>类型</th>
  							<th>描述</th>
  							<th>操作</th>
  						</tr>
  						<c:forEach items="${pageBean.records }" var="customer" varStatus="status">
  							<tr class="${status.index % 2 == 0 ? 'odd' : 'even' }">
  								<td align="center">
  									<input type="checkbox" name="ids" value="${customer.id }">	
  								</td>
  								<td>${customer.name }</td>
  								<td>${customer.gender }</td>
  								<td>${customer.birthday }</td>
  								<td>${customer.cellphone }</td>
  								<td>${customer.email }</td>
  								<td>${customer.preference }</td>
  								<td>${customer.type }</td>
  								<td>${customer.description }</td>
  								<td>
  									<a href="${pageContext.request.contextPath }/servlet/CustomerController?operate=editCustomerUI&customerId=${customer.id}">修改</a>
  									<a href="javascript:deleteOneCustomer('${customer.id}')">删除</a>
  								</td>
  							</tr>
  						</c:forEach>
  					</table>
  				</td>
  			</tr>
  		</table>
  </body>
</html>
